#!/bin/bash
set -eux

juju-log -l INFO "Getting token"
status-set maintenance "Getting token" || true
token="$(config-get token)"
for relation_id in $(relation-ids sink); do
  relation-set -r $relation_id token="$token"
done
if [[ -z "$token" ]]; then
  juju-log -l WARNING "Blocked: set the token"
  status-set blocked "Set the token" || true
else
  juju-log -l INFO "Token is $token"
  status-set active "Token is $(echo $token | cut -c 1-20)" || true
fi
